<?php
include_once 'baseModel.php';

class userModel extends baseModel{
	private $_username	=	'';
	private $_email		=	'';
	private $_fullname	=	'';
	private $_password	=	'';
	private $_gender	=	'1';
	
	function __construct()
	{
		parent::__construct();
		$this->_table	=	'users';
		$this->_primakey	=	'id';
	}
	
	function set_username($username = null)
	{
		$this->_username	=	$username;
	}
	
	function set_email($email = null)
	{
		$this->_email	=	$email;
	}
	
	function set_fullname($fullname = null)
	{
		$this->_fullname	=	$fullname;
	}
	
	function check_login($user, $pass)
	{
		global $DB;
		$pass	=	md5($pass);
		$row	=	$DB->query("SELECT * FROM users WHERE username='$user' AND password='$pass' AND status='active'");
		$row	=	$DB->fetch_row($row);
		if($row)
			return $row;
		return null;
	}
	
	function check_existed_email($email = '')
	{
		$sql	=	"SELECT * FROM $this->_table WHERE email='$email'";
		$row	=	$this->row($sql);
		if($row)
			return $row;
		return false;
	}
	
	function check_existed_username($username = '')
	{
		$sql	=	"SELECT * FROM $this->_table WHERE username='$username'";
		$row	=	$this->row($sql);
		if($row)
			return $row;
		return false;
	}
	
	function get_by_id($id)
	{
		$sql	=	"SELECT * FROM $this->_table WHERE id=$id";
		$row	=	$this->row($sql);
		return $row;
	}
	
	function is_login()
	{
		if(isset($_SESSION['user']) && $_SESSION['user'])
		{
			return $_SESSION['user'];
		}
		return false;
	}
	
	function get_username()
	{
		return $this->_fullname;
	}
	
	function get_email()
	{
		return $this->_email;
	}
	
	function get_fullname()
	{
		return $this->_fullname;
	}
	
	function test()
	{
		echo 'asasasasas';
	}
}
?>